var W3CDOM = (document.getElementsByTagName && document.createElement);
var firstError;

SafeAddOnload(setupDurationDropdown)

function setupDurationDropdown () {
   var selectBox = document.getElementById('durationHours')
   if (selectBox) {
       reverseUpdateDuration()
       document.getElementById('durationHours').onchange = function () {
           return updateDuration()
       }
       document.getElementById('durationDays').onchange = function () {
           return updateDuration()
       }
       document.getElementById('durationMinutes').onchange = function () {
           return updateDuration()
       }
   }
} 

function reverseUpdateDuration() {
   var splitDuration = document.getElementById('duration').value.split(" ")
   var days = parseInt(splitDuration[0])
   splitDuration = splitDuration[1].split(":")
   var hours = parseInt(splitDuration[0])
   var minutes = parseInt(splitDuration[1])

   document.getElementById('durationDays').selectedIndex = parseInt(days)
   document.getElementById('durationHours').selectedIndex = parseInt(hours)
   document.getElementById('durationMinutes').selectedIndex = (parseInt(minutes)/10)
}


function updateDuration() {
   var days = document.getElementById('durationDays').selectedIndex
   var hours = document.getElementById('durationHours').selectedIndex
   var mins = document.getElementById('durationMinutes').selectedIndex * 10

   document.getElementById('duration').value = days + ' ' + hours + ':' + mins

   removeError2(document.getElementById('duration'))
}

 function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }